<template>
  <div>
      <MyHeader></MyHeader>

	

	

	<div class="breadcrumb">
		<a href="#">全部分类</a>
		<span>></span>
		<a href="#">{{goods.cate.name}}</a>
		<span>></span>
		<a href="#">商品详情</a>
	</div>

	<div class="goods_detail_con clearfix">
		<div class="goods_detail_pic fl"><img :src="'http://127.0.0.1:8000'+goods.pic" width="280px"></div>

		<div class="goods_detail_list fr">
			<h3>{{goods.name}}</h3>
			<p>{{goods.desc}}</p>
			<div class="prize_bar">
				<span class="show_pirze">¥<em>{{goods.price}}</em></span>
				<span class="show_unit">单  位：{{goods.unit}}</span>
			</div>
			<div class="goods_num clearfix">
				<div class="num_name fl">数 量：</div>
				<div class="num_add fl">
					<input type="text" class="num_show fl" value="1" v-model="num">
					<a href="javascript:;" class="add fr" @click="num=num+1">+</a>
					<a href="javascript:;" class="minus fr" @click="num=num-1">-</a>	
				</div> 
			</div>
			<div class="total">总价：<em>{{ (num * goods.price).toFixed(2) }}元</em></div>
			<div class="operate_btn">
				<a href="javascript:;" class="buy_btn">立即购买</a>
				<a href="javascript:;" class="add_cart" id="add_cart" @click="buy">加入购物车</a>				
			</div>
		</div>
	</div>

	<div class="main_wrap clearfix">
		<div class="l_wrap fl clearfix">
			<div class="new_goods">
				<h3>新品推荐</h3>
				<ul>
					<li>
						<a href="#"><img src="../assets/images/goods/goods001.jpg"></a>
						<h4><a href="#">进口柠檬</a></h4>
						<div class="prize">￥3.90</div>
					</li>
					<li>
						<a href="#"><img src="../assets/images/goods/goods002.jpg"></a>
						<h4><a href="#">玫瑰香葡萄</a></h4>
						<div class="prize">￥16.80</div>
					</li>
				</ul>
			</div>
		</div>

		<div class="r_wrap fr clearfix">
			<ul class="detail_tab clearfix">
				<li :class="{'active':tab==1}" @click="tab=1">商品介绍</li>
				<li :class="{'active':tab==2}" @click="tab=2">评论</li>
			</ul>

			<div class="tab_content" v-show="tab==1">
				<dl>
					<dt>商品详情：</dt>
					<dd> {{goods.content}}</dd>
				</dl>
			</div>
            <div class="tab_content" v-show="tab==2">
			<dl>
				<dt>商品评论：</dt>
				<dd> 张三说:很好吃 </dd>
			</dl>
		</div>

		</div>
	</div>

	<!-- <div class="footer">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2016 北京天天生鲜信息技术有限公司 All Rights Reserved</p>
		<p>电话：010-****888    京ICP备*******8号</p>
	</div>
	<div class="add_jump"></div> -->
	<MyCertification></MyCertification>
  </div>
</template>

<script>
import mycertification from './common/Certification'
import myheader from './common/Header'
export default {
	components:{
		'MyCertification':mycertification,
		"MyHeader":myheader,
	},
    data(){
        return{
            id:this.$route.query.id,
            goods:{
                cate:''
            },
            num:1,
            tab:1,
			username:sessionStorage.getItem('username')
        }
    },created(){
        this.axios.get('/goodsdetail?id='+this.id).then(resp=>{
            console.log(resp.data)
            this.goods=resp.data
        }).catch(error=>{
            console.log(error)
        })
    },methods:{
		buy(){
			const token=sessionStorage.getItem('token')
			if(!token){
				alert('请先登录，在购买')
			}else{
				this.axios.post('/cart',{"goods":this.goods.id,"num":this.num},{'params':{'token':token}}).then(resp=>{
			console.log(resp.data)
			alert(resp.data.msg)
		}).catch(error=>{
			console.log(error)
		})
			}
		},
		search(){
		this.$router.push('/search')
	}
	}
}
</script>

<style>

</style>